set more off
local a 16

***Individual quest. at 16
use "Data/NCDS/UKDA-5565-stata11/stata11/ncds0123.dta", clear
qui ds, not(varl "ncdsid serial number"|varl "3I *") 
drop `r(varlist)'


*** AGE 16

* rename serial number
rename ncdsid  NCDSID  

local a 16

********************************************************************************
* Job preferences and expectations
********************************************************************************

* preferred first job
rename n2770 Pref1stJob_`a'
recode Pref1stJob_`a' (-1 8 9 =.) (0 7=5)
replace Pref1stJob_`a'=6 if n2771==17 /* reallocate sports*/

* likely first full-time job
rename  n2773 Exp1stJob_`a'
recode Exp1stJob_`a' (-1 8 9 =.) (0 7=5)
replace Exp1stJob_`a'=6 if n2774==17 /* reallocate sports*/

ta Exp1stJob_16, gen(IExp1stJob_16)
rename IExp1stJob_16* IExp1stJob*_16

ta Pref1stJob_16, gen(IPref1stJob_16)
rename IPref1stJob_16* IPref1stJob*_16

********************************************************************************
* Ability self ratings by subject
********************************************************************************


rename n2748 AbSlMath_`a'
rename n2749 AbSlEnglish_`a'
rename n2750 AbSlScience_`a'
rename n2751 AbSlArt_`a'
rename n2752 AbSlMusic_`a'
rename n2753 AbSlPractical_`a'
rename n2754 AbSlSport_`a'

* Indicator for subject studied
local sub Math English Science Art Music Practical Sport
foreach s of local sub{
ge IStudySub`s'_`a'=1 if AbSl`s'>1 & AbSl`s'!=. 
replace IStudySub`s'_`a'=0 if IStudySub`s'_`a'!=1 & AbSl`s'!=. & AbSl`s'>0
}

* Indicators for ability rating conditional on studying
label define apitude 1 "Below average" 2 "Average" 3 "Above average", replace 
foreach s of local sub{
recode AbSl`s' (-1=.) (1=.) (2=1) (3=2) (4=3) 
label values AbSl`s' apitude
ge IAbAv`s'_`a'=(AbSl`s'==3) if AbSl`s'!=. 
ge IAlAv`s'_`a'=(AbSl`s'==3|AbSl`s'==2) if AbSl`s'!=. 
}


********************************************************************************
* A level subject plans: Number of A levels (or Higher) subjects you hope to take 
* by subject group (for people who plan to continue to A levels
********************************************************************************

rename n2757 AlevelForLang_`a' 
rename n2758 AlevelArts_`a' 
rename n2759 AlevelMathSc_`a' 
rename n2760 AlevelSocSci_`a' 
rename n2761 AlevelPract_`a' 
rename n2762 AlevelOther_`a' 

local var AlevelForLang AlevelArts AlevelMathSc AlevelSocSci AlevelPract AlevelOther

egen iNoAlevel=anycount(`var'), value(-1 0)
egen Alevelhope_`a'=anymatch(`var'), value(1 2 3 4 5 6 7 8)
replace Alevelhope_`a'=. if Alevelhope_`a'==0 & iNoAlevel==0
drop iNoAlevel
label variable  Alevelhope_`a' "Hope to study A levels"


foreach v of local var{
replace `v'=5 if `v'>5 & `v'!=.
recode `v' (-1=.)
}

foreach v of local var{
replace `v'=0 if Alevelhope_`a'!=. & `v'==.
}


* number of planned A levels
egen nAlevel_`a'=rowtotal(Alevel*), mis
label variable  nAlevel_`a' "Number of A levels hope for"

* recode non-responses
local var AlevelForLang AlevelArts AlevelMathSc AlevelSocSci AlevelPract AlevelOther nAlevel Alevelhope
foreach v of local var{
replace `v'=. if n2755==-1
}

********************************************************************************
* Plan to stay in educaiton beyond age 16?
********************************************************************************

rename n2729 SStayPost16_`a'
recode SStayPost16_`a' (-1=.) (1=0) (2 3=1) (4=.)
replace SStayPost16_`a'=1 if  n2767>0 &  n2767!=.
label variable SStayPost16 "Plan education beyond age 16"
label define n2729 0 "No" 1 "Yes", replace

* recode for consistency
replace SStayPost16_`a'=1 if Alevelhope_`a'==1
replace Alevelhope_`a'=0 if SStayPost16==0
replace nAlevel_`a'=0 if SStayPost16==0

********************************************************************************
* Plan to stay attend university
********************************************************************************

ge SPlanDeg_`a'=1 if  n2767==1
replace SPlanDeg_`a'=0 if SPlanDeg_`a'==. & SStayPost16_`a'!=.

********************************************************************************
* Finish up
********************************************************************************

keep NCDSID *_`a'
rename *_`a' *_I`a'

sort NCDSID
save scratchdata/ncds_1974_flatfile.dta, replace
